﻿using System;
using Machine.Entity;
using Machine.IRepository;
using System.Linq;
using SqlSugar;

namespace Machine.Repository
{
    public class MachineWXDetailDAL : BaseDAL<MachineBXDetail>, IMachineWXDetail
    {
        public MachineWXDetailDAL()
        {
        }

        public object GetEntityByKind(string wxid, string kind)
        {
            var data = db.Queryable<MachineBXDetail, sys_user>(
                (d, appu) => new object[] {
                    JoinType.Left, d.Appliant == appu.Employee
                 })
                .Where((d) => d.WXID == wxid && d.Kind == kind)
                .Select((d, appu) => new
                {
                    wxid = d.WXID,
                    kind = d.Kind,
                    AppName = appu.UserName,
                    AppTime = d.AppTime,
                    appPhone = appu.Phone,
                    WXContent = d.WXContent,
                    Img = d.Img
                })
                .First();

            return data;
        }

        public object GetPageList(string wxid, string[] arrayAllowKind)
        {
            var list = db.Queryable<MachineBXDetail, sys_user>(
                (d, appu) => new object[] {
                    JoinType.Left, d.Appliant == appu.Employee })
                .Where((d) => d.WXID == wxid && arrayAllowKind.Contains(d.Kind))
                .Select((d, appu) => new
                {
                    wxid = d.WXID,
                    kind = d.Kind,
                    AppName = appu.UserName,
                    AppTime = d.AppTime,
                    appPhone = appu.Phone,
                    WXContent = d.WXContent,
                    Img = d.Img
                })
                .ToList();

            return list;
        }
    }
}
